/*
 * @Title Jackson.java
 * @Copyright Copyright(c) 2018
 * @Company com.lizhen
 * @author lizhen
 * @version 0.0.1
 */
package com.lizhen.core.function.jackson;

import com.lizhen.core.function.jackson.entity.Person;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;

import java.io.IOException;

/**
 * @author lizhen
 */
public class Jackson {

    /**
     * @author lizhen
     */
    public Jackson() {
    }

    /**
     * @author lizhen
     */
    public static void main(String[] args) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT);
        String jsonString = "{\"name\":\"小明\", \"age\":66}";
        try {
            // map json to person
            Person person = mapper.readValue(jsonString, Person.class);
            jsonString = mapper.writeValueAsString(person);

            System.out.println(person);
            System.out.println(jsonString);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
